#include <stdio.h>
#include <stdbool.h>
#include <string.h>

// 判断一个字符串是否由子字符串构成
bool repeatSubStr(const char *str)
{
    int length = strlen(str);
    for (int i = 1; i <= length / 2; i++)
    {
        if (length % i == 0)
        {
            bool flag = true;
            char subStr[i];
            strncpy(subStr, str, i);
            printf("%s\n", subStr);
            for (int j = 0; j < length; j += i)
            {
                if (strncmp(str + j, subStr, i) != 0)
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                return true;
            }
        }
    }
    return false;
}

int main()
{
    char *str = "abcabcabc";
    int ret = repeatSubStr(str);
    if (ret == 0)
    {
        printf("没有字串\n");
    }
    else
    {
        printf("有子串\n");
    }

    return 0;
}
